/**
 * 组织结构员工列表控制器
 */
import $_fn from '~plugins'
import './index.less'
import JSEncrypts from '~plugins/lib/js/jsencrypt.js'
//import '~plugins/lib/js/jsencrypt.js'
//require('~plugins/lib/js/jsencrypt.js')
export default ['$scope','$rootScope','$location','$ui','http','$state',function($scope,$rootScope,$location,$ui,http,$state) {
   //console.log(aa.aaaaa)
   $scope.$_fn = $_fn
	//四级按钮
	$scope.tabMenu = $_fn.getCurrMenu($location.path())
    console.log($scope.tabMenu)
    $scope.subMenu = $scope.tabMenu.children[0].children
    console.log($scope.subMenu)
	console.log('组织结构员工列表控制器')
	//四级按钮页面跳转方法
	$scope.operation = function (path,item) {
		console.log('111')
        var _path = path.split('@')
        let params = JSON.stringify(item)
        if(_path[0] == 'link'){
            console.log(path)
            $state.go(_path[1], item)
        }
        if(_path[0] == 'alert'){
            $ui.modal({content:"<"+_path[1]+" params="+params+"></"+_path[1]+">"})
        }
   }
	//企业授权码
	$scope.qiYeMa=function(){
		http.post('getCompanyCredit.do',{},function (data) {
            if(data.errcode > 0){
                $scope.$apply(function () {
                	$scope.param8=data.data
                    $scope.param3.cid=data.data.company_id
                    $scope.param3.code=data.data.code
                  //  $scope.param3.domainName= 'http://192.168.1.11';  
                })
            }else{
            	$ui.toast({
					text:data.errmsg,
					type:'warning'
				})
            }
		})
	}
	$scope.qiYeMa()
	//征信查询初始化
	$scope.freeReportSearch=true;//免授权
	$scope.reportSearch=false;//授权
	$scope.reportSet = function() {
		$scope.freeReportSearch = false
		$scope.reportSearch = true
		$scope.reportDataSet1 = true
		$scope.reportDataSet2 = false
		$scope.reportDataSet3 = false
		$scope.reportDataSet4 = false
	}
	$scope.freeReportSet = function() {
		$scope.freeReportSearch = true
		$scope.reportSearch = false
		$scope.reportDataSet1 = false
		$scope.reportDataSet2 = false
		$scope.reportDataSet3 = false
		$scope.reportDataSet4 = false
	}
	//根据订单号获取免授权信息
	$scope.param1={}
	$scope.param2={}
	$scope.xinXi=function(){
		console.log($scope.param1.loan_number)
		http.post('unAuthorizedSelect.do',$scope.param1,function (data) {
            if(data.errcode > 0){
                $scope.$apply(function () {
                    $scope.param2.id_card=data.data.id_card;
                    $scope.param2.real_name=data.data.real_name
                    $scope.param2.homephone=data.data.phone
                })
            }else{
            	$scope.param1.loan_number='';
            	$scope.$apply();
            	$ui.toast({
					text:data.errmsg,
					type:'warning'
				})
            }
		})
	}
	var encrypt1 = new JSEncrypts.JSEncrypt();//公钥对象
	var encrypt2 = new JSEncrypts.JSEncrypt();//私钥对象
	//公钥
	encrypt1.setPublicKey("MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCo9yyyvSUdMIu+Q3FniJuzFSfYyOc0UHZ/JGyWqwTlIgWxyAm6AcyRTzP//L6JdQ6+u8QSRWTmWW+dMSeGm0tYVAobGvTGG1eIduhE1RMqGYDbHzlCzTgkfvMIEpRncjzQYMDtlXH+i+sVeIEgM+eJnnCgRte5vicHKKkFmlg8LQIDAQAB");
	//私钥
	encrypt2.setPrivateKey('MIICdgIBADANBgkqhkiG9w0BAQEFAASCAmAwggJcAgEAAoGBAKfrKjZyCf8tI52u6LEwLMgmOKdNhqjVrNhnL3c9+pU0KRYKQrmDDf7R/jI7ZTI92luTUFw4PF1AJJgkgMRWQveZryD465lLX2M+Y6QasMk/VOJtdU+iZ1TQOeCzS//Hr3GpRYHUL6Q2oUsoDRgP+bvi13ypS8BnlvhxCxyCZi2VAgMBAAECgYBurd2kB2S5ckpAe/JaIBPUVQUQmVQB4t1Lwi+SHCMXx0qxgU/bsRs/c7Bl8apRBF3x8FaOgm6fVFEKizzorKb0M8MiHhp5FjLmg5+lPMgylaYSBQbEckFGBtPx5LXG+LdRU+VIi+RJtye4xzk2URSOk6iBBuykWknZpBlrcJ9e4QJBAOck0+PaZUjbaAf2y4e6i21OPkyqkbf58R0rmva9WVcXX3rgQtj5qXJqcB501NlLaz2fVb1cwcoxqyVCM63OGckCQQC5+c5MexsOU6pi15YJWw1fnrsOeA+Lg0MLcn6N7MGgfrG2Bygobgb6X1tKKAbAWbl5n+4UXvWQ0yKaXiAkBRttAkAFxgi450qiYECf+k0pLcKvz0WFGrmbE9Yu+Vjckuw5Xa8X3aQt0UanQftc92QdrWGXX3R/z2JTz5vLyXSLAdvpAkBfz11Ds4xNxjaac1x9d2YdY+YUXzAK/NW2eQbP0TAzofGlyGwc4ApCRIwAWTyZLeBK02TRI9a5BLzn8CP4ypTFAkEAq4tAs14vKDlR97V85Tq5mUXoAjEO2I2rFX+44uqkXlESkhStW2ML93j9ziU8HMhoETQ287Ze7hTYiLv4h54E1g==')

	//参数加密
    $scope.jiaMi=function(param){
    	for(name in param){
			param[name]=encrypt1.encrypt(param[name]+'')
		}
    }
    var creditUrl='http://192.168.1.176:8080/sys/'
    //参数解密
    $scope.jieMi=function(data){
    	var datas=[]
		for(var i=0; i<data.content.length; i++){
			console.log(data.content[i])
			console.log(encrypt2.decrypt(data.content[i]))
			datas.push(encrypt2.decrypt(data.content[i]))
		}
		console.log(datas)
		console.log(datas.join('\"'))
		var dataObj=JSON.parse(datas.join('\"'))
		//$scope.url1=creditUrl+dataObj.url+'?id='+dataObj.freepid+"&&code="+encrypt1.encrypt($scope.param.companycode.code)+"&&cid="+encrypt1.encrypt($scope.param.companycode.company_id+'');
		//return creditUrl+dataObj.url+'?id='+dataObj.freepid;
		return dataObj
    }
	//征信免授权查询
	$scope.param3={}
	$scope.zhengXin1=function(){
		console.log($scope.param3);
		$scope.param3.name_free=$scope.param2.real_name;
		$scope.param3.idcard_free=$scope.param2.id_card;
		$scope.param3.phone_free=$scope.param2.homephone;
		console.log($scope.param3)
		$scope.jiaMi($scope.param3)
		console.log($scope.param3)
		http.post1('queryAccessTokenUnsafe',$scope.param3,function (data) {
			console.log(data)
            if(data.type == 1){
                $scope.data1=$scope.jieMi(data)
                $scope.url1=creditUrl+$scope.data1.url+'?id='+$scope.data1.freepid;
                console.log($scope.url1)
            }else{
            	$ui.toast({
					text:data.errmsg,
					type:'warning'
				})
            }
        },function(){
            //报错时
            $scope.isData = true
            $scope.$apply()
        },false)
		console.log('------')
		if($scope.url1){
			window.open($scope.url1);
		}
		
	}
	
	//授权查询
	$scope.lianXiRen=[//联系人关系
		{name:'关系',value:0},
		{name:'父母',value:1},
		{name:'配偶',value:2},
		{name:'兄弟姐妹',value:3},
		{name:'朋友',value:4},
		{name:'子女',value:5},
		{name:'同事',value:6},
		{name:'亲戚',value:7}
	]
	
	$scope.param4={}
	 $scope.param5={}
	$scope.xinXi1=function(){
		console.log($scope.param1.loan_number)
		http.post('authorizedSelect.do',$scope.param4,function (data) {
            if(data.errcode > 0){
                $scope.$apply(function () {
                    $scope.param5.linkList=data.data.linkList
                    $scope.param5.linkList[0].relation=0
                    $scope.param5.linkList[1].relation=0
                    $scope.param5.personal=data.data.personal
                    $scope.cityid1=$scope.param5.personal.addr_province+','+$scope.param5.personal.addr_city
                })
            }else{
            	$scope.param1.loan_number='';
            	$scope.$apply();
            	$ui.toast({
					text:data.errmsg,
					type:'warning'
				})
            }
		})
	}
	//授权查询下一步
	$scope.param6={}
	$scope.xia1=function(){
		console.log($scope.param5)
		if($scope.param6.agreePort){
			$scope.param6.agreePort=1
		}else{
			$scope.param6.agreePort=-1
		}
		$scope.param6.name = $scope.param5.personal.real_name
		$scope.param6.id_card_num = $scope.param5.personal.id_card
		$scope.param6.cell_phone_num =$scope.param5.personal.phone
		$scope.param6.province = $scope.param5.personal.addr_province
		$scope.param6.city = $scope.param5.personal.addr_city
		$scope.param6.work_addr = $scope.param5.personal.address
		$scope.param6.read_accept = $scope.param6.agreePort
		/*紧急联系人*/
		$scope.param6.contact_name= $scope.param5.linkList[0].name
		$scope.param6.contact_tel = $scope.param5.linkList[0].telephone
		$scope.param6.contact_type = $scope.param5.linkList[0].relation
		
		$scope.param6.contact_name1= $scope.param5.linkList[1].name
		$scope.param6.contact_tel1 = $scope.param5.linkList[1].telephone
		$scope.param6.contact_type1 = $scope.param5.linkList[1].relation
		$scope.param6.cid=$scope.param8.company_id
		$scope.param6.code=$scope.param8.code
		//存借款人信息到车贷
		/*$scope.param61=$scope.param6;
		$scope.param61.lid=$scope.param.linkmaninfo[0].id
		$scope.param61.lid1=$scope.param.linkmaninfo[1].id
		$scope.param61.id=$scope.param.personalId*/
		$scope.jiaMi($scope.param6)
		
		http.post1('queryCreditAccessToken1',$scope.param6,function (data) {
			console.log(data)
            if(data.type == 1){
                $scope.data2=$scope.jieMi(data)
                console.log($scope.data2);
                $scope.operation('alert@phone',{
                	phone:$scope.param5.personal.phone,
                	cid:$scope.param3.cid,
                	code:$scope.param3.code,
                	isShow:"phone",
                	msg:$scope.data2.msg,
                	name:$scope.param5.personal.real_name,
                	idcard:$scope.param5.personal.id_card
                });//跳转到手机信息页面
            }else{
            	$ui.toast({
					text:data.errmsg,
					type:'warning'
				})
            }
        },function(){
            //报错时
            $scope.isData = true
            $scope.$apply()
        },false)
	}
	//初始化对象
	$scope.param2={
		pageNum:1,
		positionId:-1,
		departmentId:-1,
		locked:-1
	}
	$scope.param1={}
	//获取数据的函数
    $scope.getDada = function(){
        //$scope.param.pageNum = page
        http.post('userListInit.do',$scope.param,function (data) {
            if(data.errcode > 0){
                //列表无数据
                if(data.data.userPage.list.length === 0){
                    $scope.isData = true
                    $scope.$apply()
                }
                $scope.$apply(function () {
                    $scope.param1.userPage = data.data.userPage;//分页
                    $scope.param1.list = data.data.userPage.list;
                    $scope.param1.positionList = data.data.positionList;//职位下拉框
                    $scope.param1.deptList = data.data.deptList;//部门下拉框
                    $scope.param1.roles = data.data.roles;//角色下拉框
                })
            }else{
            	$ui.toast({
					text:data.errmsg,
					type:'warning'
				})
            }
        },function(){
            //报错时
            $scope.isData = true
            $scope.$apply()
        })
    }
	$scope.getDada()
    $scope.select = [{name:'以租代购',value:1},{name:'信贷方式',value:2}]
    $scope.popup = {
        opened: true
    }
    $scope.open = function () {
        $scope.popup.opened = !$scope.popup.opened
    }
}]
